package bysj.service;

import bysj.dao.ProfTitleDao;
import bysj.domain.ProfTitle;
import util.Condition;
import util.JdbcHelper;
import util.Pagination;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.Collection;
import java.util.List;

public final class ProfTitleService {
	private static ProfTitleDao profTitleDao= ProfTitleDao.getInstance();
	private static ProfTitleService profTitleService=new ProfTitleService();
	private ProfTitleService(){}

	public static ProfTitleService getInstance(){
		return profTitleService;
	}

	public Collection<ProfTitle> findAll(List<Condition> conditionList, Pagination pagination) throws SQLException {
		Connection connection = JdbcHelper.getConn();
		Collection<ProfTitle> profTitles = profTitleDao.findAll(connection,conditionList,pagination);
		JdbcHelper.close(connection);
		return profTitles;
	}

	public ProfTitle find(Integer id) throws SQLException {
		Connection connection = JdbcHelper.getConn();
		ProfTitle profTitle = profTitleDao.find(id,connection);
		JdbcHelper.close(connection);
		return profTitle;
	}

	public boolean update(ProfTitle profTitle) throws SQLException {
		Connection connection = JdbcHelper.getConn();
		boolean updated = profTitleDao.update(profTitle,connection);
		JdbcHelper.close(connection);
		return updated;
	}

	public boolean add(ProfTitle profTitle) throws SQLException {
		Connection connection = JdbcHelper.getConn();
		boolean added = profTitleDao.add(profTitle,connection);
		JdbcHelper.close(connection);
		return added;
	}

	public boolean delete(Integer id) throws SQLException {
		Connection connection = JdbcHelper.getConn();
		boolean deleted = profTitleDao.delete(id,connection);
		JdbcHelper.close(connection);
		return deleted;
	}
}

